package com.cangsan.erhai.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cangsan.erhai.entity.SysRole;
import com.cangsan.erhai.entity.SysUserRole;
import com.cangsan.erhai.mapper.SysRoleMapper;
import com.cangsan.erhai.mapper.SysUserRoleMapper;
import com.cangsan.erhai.service.SysUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author 76118
* @description 针对表【sys_user_role(用户和角色关联表)】的数据库操作Service实现
* @createDate 2024-09-17 16:11:19
*/
@Service
public class SysUserRoleServiceImpl extends ServiceImpl<SysUserRoleMapper, SysUserRole>
    implements SysUserRoleService{
    @Autowired
    SysRoleMapper sysRoleMapper;


    @Override
    public Map<String, List<SysRole>> roleByUserId(Long userId) {

        QueryWrapper<SysRole> getByRoleId = Wrappers.<SysRole>query().inSql("role_id", "select role_id from sys_user_role where user_id=" + userId);
        getByRoleId.select("role_id","role_name");
        getByRoleId.eq("is_del",0);
        List<SysRole> inRole = sysRoleMapper.selectList(getByRoleId);

        QueryWrapper<SysRole> notIn = Wrappers.<SysRole>query().notInSql("role_id", "select role_id from sys_user_role where user_id=" + userId);
        notIn.select("role_id","role_name");
        notIn.eq("is_del",0);
        List<SysRole> notRole = sysRoleMapper.selectList(notIn);
        Map<String, List<SysRole>> res = new HashMap<>();
        res.put("inRole",inRole);
        res.put("notRole",notRole);
        return res;
    }
}




